package com.test.controllers;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.test.services.EmailSenderService;
import com.test.services.RegisterUserService;

public class RegistrationPart2Activity extends Activity {

	private static final String TAG = "Registration2Activity";
	private Button btnRegister;

	String dob;

	EmailSenderService email = new EmailSenderService();
	String emailaddress = "";
	String firstname = "";
	String gender = "";
	String password = "";
	RegisterUserService registerUserService = new RegisterUserService();
	String surname = "";
	String username = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.registration_part2);

	
		Bundle extras = getIntent().getExtras();

		if (extras != null) {
			username = extras.getString("username");
			password = extras.getString("password");
			emailaddress = extras.getString("email");
		}
		
		Log.d(TAG, "Get Bundle user name: " + username);
		Log.d(TAG, "Get Bundle password: " + password);
		Log.d(TAG, "Get Bundle email: " + emailaddress);

		btnRegister = (Button) findViewById(R.id.button1);
		btnRegister.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

//				firstname = txtfirstName.getText().toString();
//				
//				surname = txtsurName.getText().toString();
//				dob = txtDOB.getText().toString();
//				gender = txtGender.getText().toString();
//				
//				
//				Log.d(TAG, "First name: " + firstname);
//				Log.d(TAG, "Surname: " + surname);
//				Log.d(TAG, "DOB: " + dob);
//				Log.d(TAG, "Gender: " + gender);
//
//				if (firstname.matches("") || surname.matches("")
//						|| gender.matches("")) {
//					Log.d(TAG,
//							"One or more editboxes empty. Throwing dialogbox");
//					dialogBox("Please fill in all the details on this screen.",
//							"Missing details.");
//				} else {
//
//					Log.d(TAG, "Preparing intent to RegistrationPart2Activity");
//					Intent registrationPart2Intent = new Intent(
//							RegistrationPart2Activity.this,
//							MainMenuActivity.class);
//
//					registrationPart2Intent.putExtra("username", username);
//					Log.d(TAG, "Intent Username: " + username);
//					registrationPart2Intent.putExtra("password", password);
//					Log.d(TAG, "Intent password: " + password);
//					registrationPart2Intent.putExtra("email", emailaddress);
//					Log.d(TAG, "Intent email: " + emailaddress);
//					registrationPart2Intent.putExtra("firstname", firstname);
//					Log.d(TAG, "Intent Firstname: " + firstname);
//					registrationPart2Intent.putExtra("surname", surname);
//					Log.d(TAG, "Intent surname: " + surname);
//					registrationPart2Intent.putExtra("dob", dob);
//					Log.d(TAG, "Intent dob: " + dob);
//					registrationPart2Intent.putExtra("gender", gender);
//					Log.d(TAG, "Intent gender: " + gender);

					Log.d(TAG,
							"Navigating via intent to RegistrationPart2Activity");
//					startActivity(registrationPart2Intent);
//				}

			}
		});
	}

	@SuppressWarnings("unused")
	private void dialogBox(String messageDisplayText, String Title) {

		String msg = messageDisplayText;
		String title = Title;

		AlertDialog.Builder builder = new AlertDialog.Builder(
				RegistrationPart2Activity.this);

		builder.setMessage(msg).setCancelable(false)
				.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int id) {
						Log.d(TAG, "Preparing intent to LoginActivity");
						Intent intent = new Intent(
								RegistrationPart2Activity.this,
								LoginActivity.class);
						Log.d(TAG, "Starting intent to LoginActivity");
						startActivity(intent);
					}
				});
		AlertDialog alert = builder.create();
		alert.setTitle(title);
		alert.show();
	}

}
